package elijah.base.widget;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;

import androidx.annotation.NonNull;

import com.lxj.xpopup.core.BasePopupView;

import elijah.base.databinding.ViewClearEdittextBinding;
import elijah.base.databinding.ViewClearEdittextMiltiLineBinding;
import elijah.base.dialog.BaseItemCreateView;
import elijah.base.dialog.api.OnActionCallback;

public class MultiLineEditTextDialog extends BaseItemCreateView.IContentView<String, ViewClearEdittextMiltiLineBinding> {

    public MultiLineEditTextDialog(@NonNull Context context) {
        super(context);
        binding.btClear.setOnClickListener(v -> {
            binding.editText.setText("");
            binding.editText.requestFocus();
        });


    }

    @Override
    public void onSubmit(OnActionCallback<String> callback, BasePopupView dialog) {
        callback.onSubmit(getText(), dialog);

    }

    public void setText(String text) {
        binding.editText.setText(text);
    }

    public String getText() {
        return binding.editText.getText().toString();
    }

    public void show(String title, OnActionCallback<String> onActionCallback) {
        new BaseItemCreateView.Builder<String>(getContext())
                .setTitle(title)
                .setViewWidth(0.4f)
                .setContentView(this)
                .setActionCallback(new OnActionCallback.Impl<String>() {
                    @Override
                    public void onSubmit(String value, BasePopupView dialog) {
                        onActionCallback.onSubmit(value, dialog);
                    }
                }).show();
    }
}
